package ru.averta.notes.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import ru.averta.notes.domain.abstr.AbstractPersistentObject;
import ru.averta.notes.domain.flags.ITagable;
import ru.averta.notes.other.UtilsCommon;

@Entity
@Table(name = "Tag_Connector")
public class TagConnector extends AbstractPersistentObject {

	@Column(name = "OBJECT_CLASS")
	private String objectClass;
	
	@Column(name = "OBJECT_ID")
	private Long objectId;
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="TAG_ID")
	private Tag tag;
	
	public TagConnector() {
		
	}
	
	public TagConnector(ITagable object, Tag tag) {
		setObject(object);
		setTag(tag);
	}
	
	private void setObject(ITagable object) {
		objectClass = UtilsCommon.getClassName(object);
		objectId = object.getId();
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	public Tag getTag() {
		return tag;
	}
	
	
}
